#ifndef _BOUNDINGTRIANGLE_H
#define _BOUNDINGTRIANGLE_H

#include "vector2.h"
#include "vector3.h"

class BoundingTriangle
{
public:
	BoundingTriangle()
	{
	}

	BoundingTriangle(Vector2 A, Vector2 B, Vector2 C)
	{
		a = Vector3(A);
		b = Vector3(B);
		c= Vector3(C);
	}

	bool Intersects(Vector2 point)
	{
		if(SameSide(Vector3(point), a, b, c) && SameSide(Vector3(point), b, a, c) && SameSide(Vector3(point), c, a, b))
		{
			return true;
		}
		return false;
	}

private:
	Vector3 a, b, c;

	bool SameSide(Vector3 point1, Vector3 point2, Vector3 A, Vector3 B)
	{
		Vector3 crossProduct1 = (B - A).CrossProduct((point1 - A));
		Vector3 crossProduct2 = (B - A).CrossProduct((point2 - A));
		if(crossProduct1.DotProduct(crossProduct2) >= 0)
		{
			return true;
		}
		return false;
	}
};

#endif